from utils.ext import inner_db
from marshmallow import Schema, fields, ValidationError, validate, validates_schema

class IntervalQuerySchema(Schema):
    query_interval = fields.Integer(required=True, validate= validate.OneOf(choices=[7, 30]))

class PAI_PROJECT_JOB(inner_db.Model):
    __bind_key__ = 'cnbita'
    __tablename__ = 'pai_project_job'

    id = inner_db.Column(inner_db.BigInteger , primary_key=True, nullable=False)
    job_name = inner_db.Column(inner_db.String(255))
    config = inner_db.Column(inner_db.Text)
    project_id = inner_db.Column(inner_db.BigInteger)
    project_name = inner_db.Column(inner_db.String(255))
    create_time = inner_db.Column(inner_db.BigInteger)
    update_time = inner_db.Column(inner_db.BigInteger)
    del_flag = inner_db.Column(inner_db.SmallInteger, default = 0)
    job_type = inner_db.Column(inner_db.SmallInteger, default = 1)
    code_no = inner_db.Column(inner_db.SmallInteger, default = 1)

    def get_data_info(self):
        return dict(id = self.id,
                    job_name = self.job_name,
                    config = self.config,
                    project_id = self.project_id,
                    project_name = self.project_name,
                    create_time = self.create_time,
                    update_time = self.update_time,
                    del_flag = self.del_flag,
                    job_type = self.job_type,
                    code_no = self.code_no
                    )

    def __str__(self):
        return "{}".format(self.get_data_info())

    def __repr__(self):
        return "{}".format(self.get_data_info())

class PAI_PROJECT(inner_db.Model):
    __bind_key__ = 'cnbita'
    __tablename__ = 'pai_project'

    id = inner_db.Column(inner_db.BigInteger , primary_key=True, nullable=False)
    project_name = inner_db.Column(inner_db.String(255))
    user_id = inner_db.Column(inner_db.String(255))
    config = inner_db.Column(inner_db.Text)
    type = inner_db.Column(inner_db.SmallInteger, default = 0)
    profile = inner_db.Column(inner_db.String(10000))
    file_path = inner_db.Column(inner_db.String(255))
    notes = inner_db.Column(inner_db.Text)
    create_time = inner_db.Column(inner_db.BigInteger)
    update_time = inner_db.Column(inner_db.BigInteger)
    language = inner_db.Column(inner_db.String(255))
    algorithm = inner_db.Column(inner_db.String(255))
    del_flag = inner_db.Column(inner_db.SmallInteger, default = 0)
    origin = inner_db.Column(inner_db.SmallInteger, default = 0)

    def get_data_info(self):
        return dict(project_name = self.job_name,
                    user_id = self.user_id,
                    type = self.type,
                    create_time = self.create_time,
                    update_time = self.update_time,
                    language = self.language,
                    algorithm = self.algorithm
                    )

    def __str__(self):
        return "{}".format(self.get_data_info())

    def __repr__(self):
        return "{}".format(self.get_data_info())

class PAI_DATASET(inner_db.Model):
    __bind_key__ = 'cnbita'
    __tablename__ = 'pai_dataset'

    id = inner_db.Column(inner_db.BigInteger , primary_key=True, nullable=False)
    number = inner_db.Column(inner_db.String(64))
    name = inner_db.Column(inner_db.String(255))
    type = inner_db.Column(inner_db.SmallInteger, default = 0)
    is_pass = inner_db.Column(inner_db.SmallInteger)
    path = inner_db.Column(inner_db.String(255))
    container_path = inner_db.Column(inner_db.String(255))
    profile = inner_db.Column(inner_db.String(255))
    remark = inner_db.Column(inner_db.Text)
    user_id = inner_db.Column(inner_db.String(255))
    provider = inner_db.Column(inner_db.String(255))
    create_time = inner_db.Column(inner_db.BigInteger)
    update_time = inner_db.Column(inner_db.BigInteger)
    del_flag = inner_db.Column(inner_db.SmallInteger, default = 0)


class PlatformUsers(inner_db.Model):
    __bind_key__ = 'cnbita'
    __tablename__ = 'ai_user_basic_info'

    account = inner_db.Column(inner_db.String(64))

    id = inner_db.Column(inner_db.String(64), primary_key=True, nullable=False)

    username = inner_db.Column(inner_db.String(255))

    password = inner_db.Column(inner_db.String(255))

    email = inner_db.Column(inner_db.String(255))

    identify = inner_db.Column(inner_db.SmallInteger)

    position = inner_db.Column(inner_db.String(255))

    company = inner_db.Column(inner_db.String(255))

    description = inner_db.Column(inner_db.String(255))

    head_image = inner_db.Column(inner_db.String(255))

    honor = inner_db.Column(inner_db.String(255))

    active_time = inner_db.Column(inner_db.DateTime)

    is_developer = inner_db.Column(inner_db.SmallInteger)

    email_code = inner_db.Column(inner_db.String(6))

    msg_code = inner_db.Column(inner_db.String(6))

    user_source = inner_db.Column(inner_db.String(1))

    create_by = inner_db.Column(inner_db.String(64))

    create_date = inner_db.Column(inner_db.DateTime)

    update_by = inner_db.Column(inner_db.String(64))

    update_date = inner_db.Column(inner_db.DateTime)

    remarks = inner_db.Column(inner_db.String(255))

    del_flag = inner_db.Column(inner_db.String(1), default='0', nullable=False)

    token = inner_db.Column(inner_db.String(255), default='0')

    failure_time = inner_db.Column(inner_db.DateTime)

    STATUS = inner_db.Column(inner_db.String(1), default='1', nullable=False)

    manage_role = inner_db.Column(inner_db.SmallInteger, default=0)

    is_limited = inner_db.Column(inner_db.SmallInteger, default=1)

    def get_data_info(self):
        return dict(id = self.id, account = self.account, email = self.email,
                    username = self.username, is_limited= self.is_limited)

    def __str__(self):
        return "{}".format(self.get_data_info())

    def __repr__(self):
        return "{}".format(self.get_data_info())

